﻿using System;
using System.Collections.Generic;
using System.Text;
using OpenTwitter.SDK.Sina.Objects;
using OpenTwitter.SDK.Http;

namespace OpenTwitter.SDK.Sina.API
{
    /// <summary>
    /// 与关系链相关的接口实现
    /// </summary>
    public class Friends
        : APIRequest
    {
        /// <summary>
        /// 根据授权对象实例化
        /// </summary>
        /// <param name="oauth"></param>
        public Friends(OAuth oauth)
            : base(oauth)
        { }

        #region 关注某用户
        /// <summary>
        /// 采用默认API请求地址关注某用户
        /// </summary>
        /// <param name="user_id">用户的UID</param>
        /// <returns>关注人的帐号信息.</returns>
        public UserProfileData Add(long user_id)
        {
            return this.Add("http://api.t.sina.com.cn/friendships/create", user_id, null);
        }
        /// <summary>
        /// 采用默认API请求地址关注某用户
        /// </summary>
        /// <param name="screen_name">用户的账号名称</param>
        /// <returns>关注人的帐号信息.</returns>
        public UserProfileData Add(string screen_name)
        {
            return this.Add("http://api.t.sina.com.cn/friendships/create", 0, screen_name);
        }
        /// <summary>
        /// 关注某用户，其中user_id,screen_name必填其一
        /// </summary>
        /// <param name="requestUrl">API请求地址</param>
        /// <param name="user_id">用户的UID，可以为0</param>
        /// <param name="screen_name">用户的账号名称，可以为空</param>
        /// <returns>关注人的帐号信息.</returns>
        public UserProfileData Add(string requestUrl, long user_id, string screen_name)
        {
            if (user_id <= 0 && string.IsNullOrEmpty(screen_name)) return null;
            this.Clear();
            if (user_id > 0) this.Parameters.Add("user_id", user_id);
            if (!string.IsNullOrEmpty(screen_name)) this.Parameters.Add("screen_name", screen_name);
            return this.GetResponseData<UserProfileData>(RequestMethod.POST, requestUrl);
        }
        #endregion

        #region 取消关注某用户
        /// <summary>
        /// 采用默认API请求地址取消关注某用户
        /// </summary>
        /// <param name="user_id">用户的UID</param>
        /// <returns>关注人的帐号信息.</returns>
        public UserProfileData Delete(long user_id)
        {
            return this.Delete("http://api.t.sina.com.cn/friendships/destroy", user_id, null);
        }
        /// <summary>
        /// 采用默认API请求地址取消关注某用户
        /// </summary>
        /// <param name="screen_name">用户的账号名称</param>
        /// <returns>关注人的帐号信息.</returns>
        public UserProfileData Delete(string screen_name)
        {
            return this.Delete("http://api.t.sina.com.cn/friendships/destroy", 0, screen_name);
        }
        /// <summary>
        /// 取消关注某用户，其中user_id,screen_name必填其一
        /// </summary>
        /// <param name="requestUrl">API请求地址</param>
        /// <param name="user_id">用户的UID，可以为0</param>
        /// <param name="screen_name">用户的账号名称，可以为空</param>
        /// <returns>关注人的帐号信息.</returns>
        public UserProfileData Delete(string requestUrl, long user_id, string screen_name)
        {
            if (user_id <= 0 && string.IsNullOrEmpty(screen_name)) return null;
            this.Clear();
            if (user_id > 0) this.Parameters.Add("user_id", user_id);
            if (!string.IsNullOrEmpty(screen_name)) this.Parameters.Add("screen_name", screen_name);
            return this.GetResponseData<UserProfileData>(RequestMethod.POST, requestUrl);
        }
        #endregion
    }
}
